// import Nevow.Athena
// import Divmod.Runtime

Meercat.Job.Form.Base = Nevow.Athena.Widget.subclass('Meercat.Job.Form.Base');

/*
Meercat.Job.Form.Harvest.Incremental = Meercat.Job.Form.Base.subclass('Meercat.Job.Form.Harvest.Incremental');
Meercat.Job.Form.Harvest.Scheduled = Meercat.Job.Form.Base.subclass('Meercat.Job.Form.Harvest.Scheduled');
Meercat.Job.Form.Solr.Incremental = Meercat.Job.Form.Base.subclass('Meercat.Job.Form.Solr.Incremental');
Meercat.Job.Form.Solr.Scheduled = Meercat.Job.Form.Base.subclass('Meercat.Job.Form.Solr.Scheduled')
*/

Meercat.Job.Form.Base.methods(
function addJob(self) {
    var data = new Object();
    
    jQuery('#' + escapeId(self.node.id) + ' :input').each(function (input) {
        var input = jQuery(this);
    
        if (input.attr('name')) {
            data[input.attr('name')] = input.val();
        }
    });
    
    var d = self.callRemoteKw('addJob', data);
    
    d.addCallback(function (result) {
        self.widgetParent.widgetParent.refresh();
        self.widgetParent.remove();
    });
    
    d.addErrback(function (failure) {
        alert(failure);
    });
},
function remove(self) {
    var d = self.detach();
    d.addCallback(function (result) {
        jQuery('#' + escapeId(self.node.id)).remove();
    });
    
    d.addErrback(function (failure) {
        alert('Error detaching the add job form: ' + failure);
    });
});